﻿using MTUnity.Utils;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public class FCurrentSortintData
{
    public int SortingCountInPlan { get; set; }
    //已分拣量
    public int SortingCountInCompleted { get; set; }
    //分拣时间
    public double SortingDuration { get; set; }
    //效率
    public double SortingEfficient { get; set; }

    public void UpdateCurrentSortingData(int iInCompleted , int iInPlan , double dDuration , double dEfficient)
    {
        SortingCountInPlan = iInPlan;
        SortingCountInCompleted = iInCompleted;
        SortingDuration = dDuration;
        SortingEfficient = dEfficient;
    }
}

public class FSortingLine : DataBase
{
    public FSortingLine(int iID)
    {
        //ID = iID;
    }
  
    //public string Location { get; set;

    //能耗
    public double CurrentEnergyConsumption { get; set; }
    //计划分拣量
    public FCurrentSortintData CurrentSortingData = new FCurrentSortintData();
    //计划巡查点
    public int CurrentSortingCheckInPlan { get; set; }
    //已完成巡查点
    public int CurrentSortingCheckInCompleted { get; set; }



    private List<FEnergyConsumptionRecord> m_listEnergyConsumptionRecord = new List<FEnergyConsumptionRecord>();
    private List<FSortingEfficientRecord> m_listSortingEfficientRecord = new List<FSortingEfficientRecord>();
    private List<FSortingDurationRecord> m_listSortingDurationRecord = new List<FSortingDurationRecord>();
    private List<FSortingCountRecord> m_listSortingCountRecord = new List<FSortingCountRecord>();
    private List<FSortingCheckRecord> m_listCheckRecord = new List<FSortingCheckRecord>();


    public void AddEnergyConsumptionRecord(double dEnergyConsumption , long lTimestamp)
    {
        FEnergyConsumptionRecord repertory = new FEnergyConsumptionRecord()
        {
            EnergyConsumption = dEnergyConsumption,
            Timestamp = lTimestamp
        };
        m_listEnergyConsumptionRecord.Add(repertory);
    }

    public void AddSortingEfficientRecord(double dSortingEfficient, long lTimestamp)
    {
        FSortingEfficientRecord sortingEfficient = new FSortingEfficientRecord()
        {
            SortingEfficient = dSortingEfficient,
            Timestamp = lTimestamp
        };
        m_listSortingEfficientRecord.Add(sortingEfficient);
    }

    public void AddSortingDurationRecord(double dSortingDuration, long lTimestamp)
    {
        FSortingDurationRecord sortingDuration = new FSortingDurationRecord()
        {
            SortingDuration = dSortingDuration,
            Timestamp = lTimestamp
        };
        m_listSortingDurationRecord.Add(sortingDuration);
    }

    public void AddSortingCountRecord(int iSortingCountInCompleted, int iSortingCountInPlan ,long lTimestamp)
    {
        FSortingCountRecord sortingCount = new FSortingCountRecord()
        {
            SortingCountInCompleted = iSortingCountInCompleted,
            SortingCountInPlan = iSortingCountInPlan,
            Timestamp = lTimestamp
        };
        m_listSortingCountRecord.Add(sortingCount);
    }

    public void AddCheckRecordRecord(int iCheckInPlan , int iCheckInCompleted , long lTimestamp)
    {
        FSortingCheckRecord checkRecord = new FSortingCheckRecord()
        {
            SortingCheckInPlan= iCheckInPlan,
            SortingCheckInCompleted = iCheckInCompleted,
            Timestamp = lTimestamp
        };
        m_listCheckRecord.Add(checkRecord);
    }

    public List<FEnergyConsumptionRecord> GetNearestEnergyConsumptionRecord(int iCount)
    {
        return ToolUtils.GetCountFromList<FEnergyConsumptionRecord>(m_listEnergyConsumptionRecord, iCount);
    }

    public List<FSortingEfficientRecord> GetNearestSortingEfficientRecord(int iCount)
    {
        return ToolUtils.GetCountFromList<FSortingEfficientRecord>(m_listSortingEfficientRecord, iCount);
    }

    public List<FSortingDurationRecord> GetNearestSortingDurationRecord(int iCount)
    {
        return ToolUtils.GetCountFromList<FSortingDurationRecord>(m_listSortingDurationRecord, iCount);
    }

    public List<FSortingCountRecord> GetNearestSortingCountRecord(int iCount)
    {
        return ToolUtils.GetCountFromList<FSortingCountRecord>(m_listSortingCountRecord, iCount);
    }

    public List<FSortingCheckRecord> GetNearestSortingCheckRecord(int iCount)
    {
        return ToolUtils.GetCountFromList<FSortingCheckRecord>(m_listCheckRecord, iCount);
    }

    public override void InvalidDataCheck(string str)
    {
        switch (str)
        {
            case JsonFildName.SortingLine.Record_EnergyConsumption:
                ToolUtils.LimitListMaxCount<FEnergyConsumptionRecord>(m_listEnergyConsumptionRecord, RecordCount.RecordEnergyConsumption_2);
                break;
            case JsonFildName.SortingLine.Record_SortingCount:
                ToolUtils.LimitListMaxCount<FSortingCountRecord>(m_listSortingCountRecord, RecordCount.RecordSortingData_2);
                break;
            case JsonFildName.SortingLine.Record_SortingDuration:
                ToolUtils.LimitListMaxCount<FSortingDurationRecord>(m_listSortingDurationRecord, RecordCount.RecordSortingData_2);
                break;
            case JsonFildName.SortingLine.Record_SortingEfficient:
                ToolUtils.LimitListMaxCount<FSortingEfficientRecord>(m_listSortingEfficientRecord, RecordCount.RecordSortingData_2);
                break;
            case JsonFildName.SortingLine.Record_SortingCheck:
                ToolUtils.LimitListMaxCount<FSortingCheckRecord>(m_listCheckRecord, RecordCount.RecordSortingCheck);
                break;
            default:
                ToolUtils.LimitListMaxCount<FEnergyConsumptionRecord>(m_listEnergyConsumptionRecord, RecordCount.RecordEnergyConsumption_2);
                ToolUtils.LimitListMaxCount<FSortingCountRecord>(m_listSortingCountRecord, RecordCount.RecordSortingData_2);
                ToolUtils.LimitListMaxCount<FSortingDurationRecord>(m_listSortingDurationRecord, RecordCount.RecordSortingData_2);
                ToolUtils.LimitListMaxCount<FSortingEfficientRecord>(m_listSortingEfficientRecord, RecordCount.RecordSortingData_2);
                ToolUtils.LimitListMaxCount<FSortingEfficientRecord>(m_listSortingEfficientRecord, RecordCount.RecordSortingCheck);
                break;
        }
        base.InvalidDataCheck(str);
    }
}


public struct FEnergyConsumptionRecord
{
    public double EnergyConsumption { get; set; }
    public long Timestamp { get; set; }
}

public struct FSortingEfficientRecord
{
    public double SortingEfficient { get; set; }
    public long Timestamp { get; set; }
}

public struct FSortingDurationRecord
{
    public double SortingDuration { get; set; }
    public long Timestamp { get; set; }
}

public struct FSortingCountRecord
{
    public int SortingCountInCompleted { get; set; }
    public int SortingCountInPlan { get; set; }
    public long Timestamp { get; set; }
}

public struct FSortingCheckRecord
{
    public int SortingCheckInPlan { get; set; }
    public int SortingCheckInCompleted { get; set; }
    public long Timestamp { get; set; }
}